import { ref } from "vue";

/**
 * 开关状态 Hook
 * @param initialState 初始状态，默认为 false
 * @returns [当前状态, 切换函数, 设置状态函数]
 */
export default function useToggle(initialState: boolean = false) {
  const state = ref(initialState);

  /**
   * 切换状态
   */
  const toggle = () => {
    state.value = !state.value;
  };

  /**
   * 设置状态
   * @param value 要设置的值
   */
  const set = (value: boolean) => {
    state.value = value;
  };

  return [state, toggle, set] as const;
}
